package com.flymobi.wap;

import java.util.List;

import com.flymobi.fw.modules.SM;
import com.flymobi.fw.modules.cache.CacheNeedsRefreshException;
import com.flymobi.fw.util.StringUtil;
import com.flymobi.po.Zhuanti;
import com.flymobi.util.Pagination;
import com.flymobi.util.WebContext;
import com.flymobi.vo.ZhuantiSearchVo;

public class ZhuantiAction extends WapAction {
	private String type;

	/**
	 * @return the type
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param type
	 *            the type to set
	 */
	public void setType(String type) {
		this.type = type;
	}

	/**
	 * @return the param
	 */
	public ZhuantiSearchVo getParam() {
		return param;
	}

	/**
	 * @param param
	 *            the param to set
	 */
	public void setParam(ZhuantiSearchVo param) {
		this.param = param;
	}

	private ZhuantiSearchVo param;
	private static final long serialVersionUID = 1L;

	public String webProcess(WebContext context) {
		param = new ZhuantiSearchVo();
		param.setStatus(1L);
		if (StringUtil.isEmpty(type)) {
			type = "-1";
		}
		param.setType(type);
		List<Zhuanti> zhuantiList = null;
		try {
			zhuantiList = (List<Zhuanti>) SM.CacheOscache.getFromCache(
					"zhuantilist", type + "-" + startRow, 10 * 60);
		} catch (CacheNeedsRefreshException e) {
			zhuantiList = SM.ZhuantiService.list(param, startRow, pagePerSize);
			SM.CacheOscache.putInCache("zhuantilist", type + "-" + startRow,
					zhuantiList);
		}
		context.put("zhuantiList", zhuantiList);
		
		int count=0;
		try {
			count = (Integer)SM.CacheOscache.getFromCache("zhuanticount", type, 10*60);
		} catch (CacheNeedsRefreshException e) {
			count=SM.ZhuantiService.getCount(param)
			.intValue();
			SM.CacheOscache.putInCache("zhuanticount", type,  count);
		}	
		Pagination p = new Pagination(count, startRow, pagePerSize);
		p.setPageUrl("zt.html?type=" + type);
		context.put("pagenation", p);
		
		return "zhuanti";
	}
	/*
	 * @Override public long getActionid() { return C.Action.zhuanti; }
	 */
}
